﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Finder.util;
using System.Threading;

namespace Finder
{
    public partial class MainForm : Form
    {
        #region 属性
        //定时6小时读取天报情况
        private System.Timers.Timer weatherT = new System.Timers.Timer(1000 * 60 * 60 * 6);
        #endregion

        #region 初始化
        public MainForm()
        {
            InitializeComponent();

            this.WindowState = FormWindowState.Minimized;
            Login log = new Login();
            log.ShowDialog();
            this.WindowState = FormWindowState.Maximized;
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            weatherT.AutoReset = true;
            weatherT.Elapsed += new System.Timers.ElapsedEventHandler(ReadWeatherTimer_Trigger);
            weatherT.Enabled = true;

            //读取天气
            Thread weatherTread = new Thread(new ThreadStart(ReadWeather));
            weatherTread.Start();
            
        }
        #endregion

        #region 定时读取、显示天气情况
        private void ReadWeatherTimer_Trigger(object sender, EventArgs e)
        {
            ReadWeather();
        }
        //读取天气情况
        private void ReadWeather()
        {
            Weather weather = new Weather();
            weather.WeatherCallBack += new Weather.WeatherEventHandler(ShowWeather);
            weather.ReadWeather();
        }
        //显示天气情况
        private void ShowWeather(string[] weatherData)
        {
            this.BeginInvoke(new MethodInvoker(delegate() {
                lb_cityname.Text = weatherData[1] + "天气：";
                lb_weatherc.Text = weatherData[6] + " " + weatherData[5];
                pb_weatherpic.Image = new Bitmap(@"weather\" + weatherData[8]);

            }));
        }
        #endregion

        #region 控件事件
        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Comm.VisiteUrl("http://www.baidu.com");
        }

        private void uC_Menu7_Click(object sender, EventArgs e)
        {
            Forms.SystemSetting ss = new Forms.SystemSetting();
            ss.TopLevel = false;
            ss.Dock = DockStyle.Fill;
            panel_main.Controls.Add(ss);
            ss.Show();
        }
        #endregion
    }
}
